package com.zy.mc_module.utils;

import android.view.View;
import android.widget.AdapterView;

import java.util.Calendar;

/**
 * Created on 18/10/22
 * 防止Item重复点击
 */
public abstract class NoDoubleItemClickListener implements AdapterView.OnItemClickListener {
    //按钮两次点击的时间间隔不能少于230毫秒
    private static final int MIN_CLICK_DELAY_TIME = 230;
    private static long lastClickTime;

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        //点击的当前时间
        long currentTime = Calendar.getInstance().getTimeInMillis();
        if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
            lastClickTime = currentTime;
            onNoDoubleClick(parent, view, position, id);
        }
    }

    protected abstract void onNoDoubleClick(AdapterView<?> parent, View view, int position, long id);
}
